<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单卡号信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="order-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>订单号：</label>
                                <input type="text" name="orderNumber"/>
                            </li>
                            <li>
                                <label>卡号：</label>
                                <input type="text" name="lotId"/>
                            </li>
                            <li>
                                <label>客户名称：</label>
                                <select name="customerName" th:with="cus=${cwWipCustomerInfo}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${cus}" th:text="${dict.customerName}" th:value="${dict.customerName}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="wip:order:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="wip:order:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="wip:order:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="wip:order:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="wip:order:export">
                    <i class="fa fa-download"></i> 导出
                </a>
<!--                <a class="btn btn-success multiple disabled" onclick="printLotIdSmall()">-->
<!--                    <i class="fa fa-print"></i> 打印卡号小标签-->
<!--                </a>-->
<!--                <a class="btn btn-primary multiple disabled" onclick="printLotIdBig()">-->
<!--                    <i class="fa fa-print"></i> 打印卡号大标签-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
                <!--  style="table-layout:fixed;word-break:break-all;" -->
            </div>
            <!-- 打印模块 -->
            <div id="print" style="display: none"></div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-table-print-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('wipinfo:info:edit')}]];
        var removeFlag = [[${@permission.hasPermi('wipinfo:info:remove')}]];
        var prefix = ctx + "wip/order";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                exportUrl: prefix + "/export",
                modalName: "订单卡号信息",
                sortName: "weekNum",
                rememberSelected: true,
                columns: [
                {
                    field: 'state',
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '编号',
                    visible: false
                },
                {
                    field: 'weekNum',
                    title: '周',
                    sortable: true,
                    width: 100
                },
                {
                    field: 'timeFlag',
                    title: '日期',
                    sortable: true,
                    width: 100
                },
                {
                    field: 'customerName',
                    title: '客户',
                    sortable: true,
                    width: 100
                },
                {
                    field: 'orderNumber',
                    title: '订单号',
                    sortable: true,
                    width: 150
                },
                {
                    field: 'partType',
                    title: '产品类型',
                    sortable: true,
                    width: 100
                },
                {
                    field: 'tgName',
                    title: '同冠名称',
                    width: 100
                },
                {
                    field: 'partName',
                    title: '产品名称',
                    width: 150
                },
                {
                    field: 'lotId',
                    title: '卡号',
                    width: 150
                },
                {
                    field: 'mainQty',
                    title: '数量',
                    width: 50
                },
                {
                    field: 'remark',
                    title: '备注',
                    width: 500
                }]
            };
            $.table.init(options);
        });

        // 打印条形码-小标签
        function printLotIdSmall() {
            const height = 50;
            const width = 1.0;
            const fontSize = 15;
            printLotId(height, width, fontSize);
        }

        // 打印条形码-大标签
        function printLotIdBig() {
            const height = 100;
            const width = 1.5;
            const fontSize = 20;
            printLotId(height, width, fontSize);
        }

        // 打印条形码
        function printLotId(height, width, fontSize) {
            $('#print').html('');
            var lotIds = $.table.selectColumns("lotId"); // 结果是个数组

            //循环生成标签
            for (let i = 0; i < lotIds.length; i++) {
                var $barcode = $("<div class='lable'><svg class='barcode'></svg></div>");
                $('#print').append($barcode);

                //JsBarcode生成条形码
                $('.barcode:last').JsBarcode(lotIds[i], {
                    format: "CODE128", //选择要使用的条形码类型
                    width: width,//设置条之间的宽度
                    height: height, //高度
                    textMargin: 5, //设置条形码和文本之间的间距
                    fontSize: fontSize,//设置文本的大小
                    fontOptions: 'bold',
                    margin: 5
                })
            }
            //设置打印分页
            $('#print .lable').css('page-break-before', 'always');
            $('#print .lable:first').attr('');

            //打印窗口
            var newWindow = window.open("###", "_blank");
            // var docStr = '<style>' + document.getElementsByTagName("style")[0].innerHTML + '</style><div id="print">'
            //     + document.getElementById('print').innerHTML + '</div>';
            // var docStr = '<div id="print">' + document.getElementById('print').innerHTML + '</div>';
            var docStr = "<html><head><title>条形码打印</title><style type='text/css'>body { margin: 0; padding: 0; } </style></head>"
                + "<div id='print'>"
                + document.getElementById('print').innerHTML
                + "</div></html>";
            newWindow.document.write(docStr);
            newWindow.document.close();
            newWindow.print();
            newWindow.close();
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>